package class141To150;

import java.io.*;

public class JosephRingProblem {

    public static int n, k;


    public static int solve() {
        int ans = 1;
        for (int c = 2; c <= n; c++) {
            ans = (ans + k - 1) % c + 1;
        }
        return ans;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int) in.nval;
        in.nextToken();
        k = (int) in.nval;
        out.println(solve());
        out.flush();
        out.close();
        br.close();
    }
}
